class Solution {
public:
    int singleNumber(vector<int>& nums) {
        int n = nums.size();
        int ret = 0;
        for (int i = 0; i < 32; i++)
        {
            int sum = 0;
            for (auto e : nums)
            {
                if ((e >> i) & 1 == 1)
                    sum++;
            }
            if (sum % 3 == 1)
                ret |= 1 << i;

        }
        return ret;

    }
};
class Solution {
public:
    vector<int> missingTwo(vector<int>& nums) {
        int tmp = 0;
        for (auto e : nums) tmp ^= e;
        for (int i = 1; i <= nums.size() + 2; i++) tmp ^= i;
        int diff = 0;
        while (1)
        {
            if (((tmp >> diff) & 1) == 1) break;
            else diff++;
        }
        int a = 0, b = 0;
        for (auto e : nums)
            if (((e >> diff) & 1) == 1) b ^= e;
            else a ^= e;
        for (int i = 1; i <= nums.size() + 2; i++)
            if (((i >> diff) & 1) == 1) b ^= i;
            else a ^= i;
        return { a,b };


    }
};